﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.data {
    import reprise.core.*;
    import flash.filters.*;

    public class AdvancedColor implements Cloneable {

        protected var m_value:int;
        protected var m_opacity:Number;

        public static var g_htmlColors:Object = {black:0, silver:0xC0C0C0, grey:0x808080, white:0xFFFFFF, maroon:0x800000, red:0xFF0000, purple:0x800080, fuchsia:0xFF00FF, green:0x8000, lime:0xFF00, olive:0x808000, yellow:0xFFFF00, navy:128, blue:0xFF, teal:0x8080, aqua:0xFFFF, magenta:0xFF00FF};

        public function AdvancedColor(_arg1:int=0, _arg2:Number=1){
            setRGB(_arg1);
            m_opacity = _arg2;
        }
        public function setRGBComponents(_arg1:int, _arg2:int, _arg3:int):void{
            m_value = (((_arg1 << 16) | (_arg2 << 8)) | _arg3);
            m_opacity = 1;
        }
        public function rgbComponents():Object{
            var _local1:Object = {r:((m_value >> 16) & 0xFF), g:((m_value >> 8) & 0xFF), b:(m_value & 0xFF)};
            return (_local1);
        }
        public function setOpacity(_arg1:Number):void{
            m_opacity = _arg1;
        }
        public function setRGB(_arg1:int):void{
            m_value = _arg1;
            m_opacity = 1;
        }
        public function argb():uint{
            return (uint((((m_opacity * 0xFF) << 24) | m_value)));
        }
        public function rgb():int{
            return (m_value);
        }
        public function setColorString(_arg1:String):void{
            var _local2:int;
            var _local3:int;
            var _local4:int;
            var _local5:Number;
            var _local6:String;
            var _local7:uint;
            var _local8:uint;
            var _local9:Array;
            if (_arg1.charAt(0) == "#"){
                switch (_arg1.length){
                    case 4:
                        _arg1 = (_arg1 + "FF");
                    case 5:
                        _local6 = _arg1.charAt(1);
                        _local2 = parseInt((_local6 + _local6), 16);
                        _local6 = _arg1.charAt(2);
                        _local3 = parseInt((_local6 + _local6), 16);
                        _local6 = _arg1.charAt(3);
                        _local4 = parseInt((_local6 + _local6), 16);
                        _local6 = _arg1.charAt(4);
                        _local5 = (parseInt((_local6 + _local6), 16) / 0xFF);
                        break;
                    case 7:
                        _arg1 = (_arg1 + "FF");
                    default:
                        _local2 = parseInt(_arg1.substr(1, 2), 16);
                        _local3 = parseInt(_arg1.substr(3, 2), 16);
                        _local4 = parseInt(_arg1.substr(5, 2), 16);
                        _local5 = (parseInt(_arg1.substr(7, 2), 16) / 0xFF);
                };
                setRGBAComponents(_local2, _local3, _local4, _local5);
                return;
            };
            _arg1 = _arg1.toLowerCase();
            if (_arg1 == "transparent"){
                m_value = 0;
                m_opacity = 0;
                return;
            };
            if (_arg1.indexOf("rgb") == 0){
                _local7 = _arg1.indexOf("(");
                _local8 = _arg1.indexOf(")");
                _local9 = _arg1.substring((_local7 + 1), _local8).split("  ").join("").split(" ").join("").split(",");
                if (_local9.length == 3){
                    _local9.push("1");
                };
                setRGBAComponents(parseInt(_local9[0]), parseInt(_local9[1]), parseInt(_local9[2]), parseFloat(_local9[3]));
                return;
            };
            m_opacity = 1;
            m_value = g_htmlColors[_arg1];
            if (isNaN(m_value)){
                m_value = 0;
            };
        }
        public function tintFilter():ColorMatrixFilter{
            var _local1:Object = rgbComponents();
            var _local2:Array = [];
            _local2 = _local2.concat([1, 0, 0, 0, (_local1.r * m_opacity)]);
            _local2 = _local2.concat([0, 1, 0, 0, (_local1.g * m_opacity)]);
            _local2 = _local2.concat([0, 0, 1, 0, (_local1.b * m_opacity)]);
            _local2 = _local2.concat([0, 0, 0, 1, 0]);
            return (new ColorMatrixFilter(_local2));
        }
        public function setRGBA(_arg1:uint):void{
            m_opacity = ((_arg1 & 0xFF) / 0xFF);
            m_value = (_arg1 >>> 8);
        }
        public function opacity():Number{
            return (m_opacity);
        }
        public function setRGBAComponents(_arg1:int, _arg2:int, _arg3:int, _arg4:Number):void{
            setRGBComponents(_arg1, _arg2, _arg3);
            m_opacity = _arg4;
        }
        public function setAlpha(_arg1:Number):void{
            _arg1 = Math.max(0, _arg1);
            _arg1 = Math.min(100, _arg1);
            m_opacity = (_arg1 / 100);
        }
        public function clone(_arg1:Boolean=false):Cloneable{
            var _local2:AdvancedColor = new AdvancedColor(m_value);
            _local2.m_opacity = m_opacity;
            return (_local2);
        }
        public function alpha():Number{
            return ((m_opacity * 100));
        }
        public function valueOf():Object{
            return (m_value);
        }
        public function rgbaComponents():void{
            var _local1:Object = rgbComponents();
            _local1.a = m_opacity;
        }
        public function toString():String{
            var _local1:String = rgba().toString(16);
            while (_local1.length < 8) {
                _local1 = ("0" + _local1);
            };
            return (("#" + _local1));
        }
        public function setARGB(_arg1:uint):void{
            m_opacity = (((_arg1 >> 24) & 0xFF) / 0xFF);
            m_value = (_arg1 & 0xFFFFFF);
        }
        public function rgba():uint{
            return ((uint((m_value << 8)) | uint((m_opacity * 0xFF))));
        }
        public function setHSB(_arg1:Number, _arg2:Number, _arg3:Number):void{
            var _local4:Number;
            var _local5:Number;
            var _local6:Number;
            if (!isNaN(_arg2)){
                _arg2 = ((100 - _arg2) / 100);
                _arg3 = ((100 - _arg3) / 100);
            };
            if ((((((_arg1 > 300)) && ((_arg1 <= 360)))) || ((((_arg1 >= 0)) && ((_arg1 <= 60)))))){
                _local4 = 0xFF;
                _local5 = ((_arg1 / 60) * 0xFF);
                _local6 = (((360 - _arg1) / 60) * 0xFF);
            } else {
                if ((((_arg1 > 60)) && ((_arg1 <= 180)))){
                    _local4 = (((120 - _arg1) / 60) * 0xFF);
                    _local5 = 0xFF;
                    _local6 = (((_arg1 - 120) / 60) * 0xFF);
                } else {
                    _local4 = (((_arg1 - 240) / 60) * 0xFF);
                    _local5 = (((240 - _arg1) / 60) * 0xFF);
                    _local6 = 0xFF;
                };
            };
            if ((((_local4 > 0xFF)) || ((_local4 < 0)))){
                _local4 = 0;
            };
            if ((((_local5 > 0xFF)) || ((_local5 < 0)))){
                _local5 = 0;
            };
            if ((((_local6 > 0xFF)) || ((_local6 < 0)))){
                _local6 = 0;
            };
            if (!isNaN(_arg2)){
                _local4 = (_local4 + ((0xFF - _local4) * _arg2));
                _local5 = (_local5 + ((0xFF - _local5) * _arg2));
                _local6 = (_local6 + ((0xFF - _local6) * _arg2));
                _local4 = (_local4 - (_local4 * _arg3));
                _local5 = (_local5 - (_local5 * _arg3));
                _local6 = (_local6 - (_local6 * _arg3));
                _local4 = Math.round(_local4);
                _local5 = Math.round(_local5);
                _local6 = Math.round(_local6);
            };
            m_value = ((_local6 | (_local5 << 8)) | (_local4 << 16));
            m_opacity = 1;
        }
        public function hsb():Object{
            var _local1:uint = ((m_value >> 16) & 0xFF);
            var _local2:uint = ((m_value >> 8) & 0xFF);
            var _local3:uint = (m_value & 0xFF);
            var _local4:Object = {};
            _local4.b = Math.max(Math.max(_local1, _local2), _local3);
            var _local5:uint = Math.min(_local1, Math.min(_local2, _local3));
            _local4.s = ((_local4.b)<=0) ? 0 : Math.round(((100 * (_local4.b - _local5)) / _local4.b));
            _local4.b = Math.round(((_local4.b / 0xFF) * 100));
            _local4.h = 0;
            if ((((_local1 == _local2)) && ((_local2 == _local3)))){
                _local4.h = 0;
            } else {
                if ((((_local1 >= _local2)) && ((_local2 >= _local3)))){
                    _local4.h = ((60 * (_local2 - _local3)) / (_local1 - _local3));
                } else {
                    if ((((_local2 >= _local1)) && ((_local1 >= _local3)))){
                        _local4.h = (60 + ((60 * (_local2 - _local1)) / (_local2 - _local3)));
                    } else {
                        if ((((_local2 >= _local3)) && ((_local3 >= _local1)))){
                            _local4.h = (120 + ((60 * (_local3 - _local1)) / (_local2 - _local1)));
                        } else {
                            if ((((_local3 >= _local2)) && ((_local2 >= _local1)))){
                                _local4.h = (180 + ((60 * (_local3 - _local2)) / (_local3 - _local1)));
                            } else {
                                if ((((_local3 >= _local1)) && ((_local1 >= _local2)))){
                                    _local4.h = (240 + ((60 * (_local1 - _local2)) / (_local3 - _local2)));
                                } else {
                                    if ((((_local1 >= _local3)) && ((_local3 >= _local2)))){
                                        _local4.h = (300 + ((60 * (_local1 - _local3)) / (_local1 - _local2)));
                                    } else {
                                        _local4.h = 0;
                                    };
                                };
                            };
                        };
                    };
                };
            };
            _local4.h = Math.round(_local4.h);
            return (_local4);
        }
        public function equals(_arg1:AdvancedColor):Boolean{
            return ((_arg1.rgba() == rgba()));
        }

    }
}//package reprise.data 
